<?php

require "../connect_db.php";

echo "<link rel='stylesheet' type='text/css' href='css/a_style.css' />";

echo	"<div align='center'>
			<p>
			- <a href='index.php?id=sitelinks'>Overzicht</a> - <a href='index.php?id=sitelinks&new'>Nieuwe Link</a> - <a href='index.php?id=sitelinks&remove'>Link Verwijderen</a> -
			</p>
			<hr />";
			if(isset($_GET['new']))
			{
				if(isset($_POST['newlink']))
				{
					echo "<p>Nieuwe link aangemaakt</p>";
					
					$label = $_POST['label'];
					$link = $_POST['link'];
					$parentid = $_POST['parentid'];
					mysql_query("INSERT INTO sitelinks(`label`, `link`, `parentid`) VALUES('$label', '$link', '$parentid')");
				}
				else
				{
					echo "<form method='POST' action='index.php?id=sitelinks&new'>
							<p>
							Link Label: <input type='text' name='label'><br>
							Link Url: <input type='text' name='link'><br>
							Parentid: <input type='text' name='parentid' value='0'><br>
							<input type='submit' name='newlink' value='Nieuwe Link Aanmaken'>
							</p>
							</form>";
				}
			}
			else if(isset($_GET['remove']))
			{
				if(isset($_POST['removelink']))
				{
					echo "<p> Link Verwijderd </p>";
					
					$linkid = $_POST['linkid'];
					mysql_query("DELETE FROM sitelinks WHERE id = $linkid");
				}
				else
				{
					echo "<form method='POST' action='index.php?id=sitelinks&remove'>
						<p>
						Vul de link id in om de link te verwijderen:<br>
						<input type='text' name='linkid' size='8'>
						<input type='submit' name='removelink' value='Link Verwijderen'>
						</p>
						</form>";
				}
			}
			else
			{
				echo "Head-links:
					<table border='1'>
						<tr>
							<td><b>id</b></td>
							<td><b>Label</b></td>
							<td><b>Sitelink</b></td>
							<td><b>Parentid</b></td>";
				
							$link_result = mysql_query("SELECT id, label, link, parentid FROM sitelinks");	
							while($link_row = mysql_fetch_array($link_result))
							{
								if($link_row['parentid'] == 0)
								{
									echo "<tr>
											<td>".$link_row['id']."</td>
											<td>".$link_row['label']."</td>
											<td>".$link_row['link']."</td>
											<td>".$link_row['parentid']."</td>
										</tr>";
								}
							}
			
				echo	"</table>
							</div>
							<br />
							<div align='center'>
								Sub-links:
								<table border='1'>
									<tr>
										<td><b>id</b></td>
										<td><b>Label</b></td>
										<td><b>Sitelink</b></td>
										<td><b>Parentid</b></td>";
				
									$link_result = mysql_query("SELECT id, label, link, parentid FROM sitelinks");	
									while($link_row = mysql_fetch_array($link_result))
									{
										if($link_row['parentid'] != 0)
										{
											echo "<tr>
													<td>".$link_row['id']."</td>
													<td>".$link_row['label']."</td>
													<td>".$link_row['link']."</td>
													<td>".$link_row['parentid']."</td>
												</tr>";
										}
									}
			
echo	"</table>
		</div>
		<hr />
		";
			}

?>